﻿@{
    ViewBag.Title = "车辆状态列表";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <script src="../Scripts/jquery.AnkeExtend.js"> </script>
    <script type="text/javascript">
       
        //页面动态改动
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        });

        //页面初始化
        $(document).ready(function () {
            DisableBackspace();
            $('#editWindow').window('close'); // 默认隐藏查看详细信息窗口

            //取所属分中心的下拉框的值
            $("#center").combobox({
                url: '@Url.Content("~/BB/AllDictionary/GetCenterName")',
                valueField: 'ID',
                textField: 'Name',
                editable: false,
                multiple: true,
                prompt: '--请选择--',
                onSelect: function (rec) {
                    var ids = $('#center').combobox('getValues');
                    //根据分中心取分站
                    $("#station").combobox({
                        url: '@Url.Content("~/BB/AllDictionary/GetSationName?centerID=")' + ids,
                        method: 'POST',
                        valueField: 'ID',
                        textField: 'Name',
                        multiple: true,
                        editable: false,
                        onSelect: function () {
                            $('#station').combobox('getValues');
                            var sids = $('#station').combobox('getValues');
                            //根据分站取车辆
                            $("#actualNumber").combobox({
                                url: '@Url.Content("~/BB/AllDictionary/GetAmbulanceName?stationID=")' + sids,
                                method: 'POST',
                                valueField: 'ID',
                                textField: 'Name',
                                multiple: true,
                                editable: false,
                                onSelect: function () {
                                    $('#actualNumber').combobox('getValues')
                                },
                                onUnselect: function () {
                                    $('#actualNumber').combobox('getValues')
                                }
                            });
                        },
                        onUnselect: function () {
                            $('#station').combobox('getValues');
                            var sids = $('#station').combobox('getValues');
                            //根据分站取车辆
                            $("#actualNumber").combobox({
                                url: '@Url.Content("~/BB/AllDictionary/GetAmbulanceName?stationID=")' + sids,
                                method: 'POST',
                                valueField: 'ID',
                                textField: 'Name',
                                multiple: true,
                                editable: false,
                                onSelect: function () {
                                    $('#actualNumber').combobox('getValues')
                                },
                                onUnselect: function () {
                                    $('#actualNumber').combobox('getValues')
                                }
                            });
                        }
                    });
                    $("#station").combobox('clear');
                    $("#actualNumber").combobox('clear');
                },
                onUnselect: function (rec) {
                    var ids = $('#center').combobox('getValues');
                    //根据分站取车辆
                    $("#station").combobox({
                        url: '@Url.Content("~/BB/AllDictionary/GetSationName?centerID=")' + ids,
                        method: 'POST',
                        valueField: 'ID',
                        textField: 'Name',
                        multiple: true,
                        editable: false,
                        onSelect: function () {
                            $('#station').combobox('getValues');
                            var sids = $('#station').combobox('getValues');
                            //根据分站取车辆
                            $("#actualNumber").combobox({
                                url: '@Url.Content("~/BB/AllDictionary/GetAmbulanceName?stationID=")' + sids,
                                method: 'POST',
                                valueField: 'ID',
                                textField: 'Name',
                                multiple: true,
                                editable: false,
                                onSelect: function () {
                                    $('#actualNumber').combobox('getValues')
                                },
                                onUnselect: function () {
                                    $('#actualNumber').combobox('getValues')
                                }
                            });
                            $("#actualNumber").combobox('clear');
                        },
                        onUnselect: function () {
                            $('#station').combobox('getValues');
                            var sids = $('#station').combobox('getValues');
                            //根据分站取车辆
                            $("#actualNumber").combobox({
                                url: '@Url.Content("~/BB/AllDictionary/GetAmbulanceName?stationID=")' + sids,
                                method: 'POST',
                                valueField: 'ID',
                                textField: 'Name',
                                multiple: true,
                                editable: false,
                                onSelect: function () {
                                    $('#actualNumber').combobox('getValues')
                                },
                                onUnselect: function () {
                                    $('#actualNumber').combobox('getValues')
                                }
                            });
                            $("#actualNumber").combobox('clear');
                        }
                    });
                    $("#station").combobox('clear');
                    $("#actualNumber").combobox('clear');
                }

            });

            var centers = $('#center').combobox('getValues');
            $("#station").combobox({
                url: '@Url.Content("~/BB/AllDictionary/GetSationName?centerID=")' + centers,
                method: 'POST',
                valueField: 'ID',
                textField: 'Name',
                multiple: true,
                editable: false,
                prompt: '--请选择--',
                onSelect: function () {
                    $('#station').combobox('getValues');
                    var sids = $('#station').combobox('getValues');
                    //根据分中心取分站
                    $("#actualNumber").combobox({
                        url: '@Url.Content("~/BB/AllDictionary/GetAmbulanceName?stationID=")' + sids,
                        method: 'POST',
                        valueField: 'ID',
                        textField: 'Name',
                        multiple: true,
                        editable: false,
                        onSelect: function () {
                            $('#actualNumber').combobox('getValues')
                        },
                        onUnselect: function () {
                            $('#actualNumber').combobox('getValues')
                        }
                    });
                },
                onUnselect: function () {
                    $('#station').combobox('getValues');
                    var ids = $('#station').combobox('getValues');
                    //根据分站取车辆
                    $("#actualNumber").combobox({
                        url: '@Url.Content("~/BB/AllDictionary/GetAmbulanceName?stationID=")' + ids,
                        method: 'POST',
                        valueField: 'ID',
                        textField: 'Name',
                        multiple: true,
                        editable: false,
                        onSelect: function () {
                            $('#actualNumber').combobox('getValues')
                        },
                        onUnselect: function () {
                            $('#actualNumber').combobox('getValues')
                        }
                    });

                }
            });

            //取实际标识
            $.EUIcombobox("#actualNumber", {
                url: '@Url.Content("~/DD/EventInfo/GetAmbulanceCode/")',
                valueField: 'ID',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //取司机
            $.EUIcombobox("#driver", {
                url: '@Url.Content("~/DD/EventInfo/GetDriver/")',
                valueField: 'Name',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //取医生
            $.EUIcombobox("#doctor", {
                url: '@Url.Content("~/DD/EventInfo/GetDoctor/")',
                valueField: 'Name',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //取护士
            $.EUIcombobox("#nurse", {
                url: '@Url.Content("~/DD/EventInfo/GetNurse/")',
                valueField: 'Name',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //取担架员
            $.EUIcombobox("#stretcher", {
                url: '@Url.Content("~/DD/EventInfo/GetStretcher/")',
                valueField: 'Name',
                textField: 'Name',
                editable: true,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });
            //取工作状态
            $.EUIcombobox("#workState", {
                url: '@Url.Content("~/DD/AmbulanceState/GetWorkState/")',
                valueField: 'ID',
                textField: 'Name',
                editable: false,
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });

            bindGrid();
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        })

        function bindGrid() {
            $('#grid').datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                striped: true,
                singleSelect: true,
                url: '@Url.Content("~/DD/AmbulanceState/DataLoad")',
                loadMsg: '数据加载中请稍后……',
                pagination: true,//启用分页
                rownumbers: true,//显示页码
                pageSize: 15,//设置 页容量
                pageList: [10, 15, 20],//设置 页容量下拉框
                sortName: '生成任务时刻',
                sortOrder: 'desc',
                remoteSort: true,
                queryParams: {
                    center: $('#center').combobox('getValues').join(','),
                    station: $('#station').combobox('getValues').join(','),
                    actualNumber: $('#actualNumber').combobox('getValue'),
                    ambulanceNumber: $('#ambulanceNumber').textbox('getValue'),
                    driver: $('#driver').combobox('getValue'),
                    doctor: $('#doctor').combobox('getValue'),
                    nurse: $('#nurse').combobox('getValue'),
                    stretcher: $('#stretcher').combobox('getValue'),
                    workState: $('#workState').combobox('getValue')
                },
                columns: [[
                   { title: '分中心', field: 'center', width: '8%', align: "center", sortable: false },
                   { title: '分站', field: 'station', width: '8%', align: "center", sortable: false },
                   { title: '车辆编码', field: 'AmbCode', width: '10%', align: "center", sortable: false, hidden: true },
                   { title: '车辆类型', field: 'ambulanceType', width: '8%', align: "center", sortable: false },
                   { title: '车牌号码', field: 'ambulanceNumber', width: '8%', align: "center", sortable: false },
                   { title: '实际标识', field: 'actualNumber', width: '8%', align: "center", sortable: false },
                   { title: '工作状态', field: 'workState', width: '8%', align: "center", sortable: true },
                   { title: '司机', field: 'driver', width: '8%', align: "center", sortable: false },
                   { title: '医生', field: 'doctor', width: '8%', align: "center", sortable: false },
                   { title: '护士', field: 'nurse', width: '8%', align: "center", sortable: false },
                   { title: '担架员', field: 'stretcher', width: '8%', align: "center", sortable: false },
                   { title: '抢救员', field: 'Rescue', width: '8%', align: "center", sortable: false },
                   { title: '随车电话', field: 'Tel', width: '11%', align: "center", sortable: false },
                   { title: '生成任务时刻', field: 'taskGenerationTime', width: '16%', align: "center", sortable: false },
                   { title: '事件编码', field: 'EventCode', width: '10%', align: "center", sortable: false, hidden: true },
                ]],
                onClickRow: function (index, data) {
                    var selected = $('#grid').datagrid('getSelected');
                    if (selected) {
                        //20161020 刘爱青 edit 有任务的可以查看任务详情
                        if (selected.EventCode != "")
                        { $('#btnViewTask').linkbutton("enable"); }
                        else
                        { $('#btnViewTask').linkbutton("disable"); }
                    }
                },
                toolbar: [
                    {
                        id: 'btnViewTask',
                        text: '<span style="color:red;font-size:normal">查看最近一次任务详情</span>',
                        iconCls: 'icon-redo',
                        handler: function () {
                            var selected = $('#grid').datagrid('getSelected');
                            if (selected) {
                                if (selected.EventCode != "")
                                    window.open('@Url.Content("~/DD/AcceptEvent/AcceptEventTaskList?EventCode=")' + selected.EventCode);
                                else {
                                    $.messager.alert('提示', '没有相关任务可查看', 'info', function () {
                                    });
                                }
                            } else {
                                $.messager.alert('提示', '请选择数据行', 'info', function () {
                                });
                            }
                        }
                    }
                    , '-',
               {
                   id: 'btnViewAmb',
                   text: '查看车辆状态',
                   iconCls: 'icon-search',
                   handler: function (jsData) {
                       var selected = $('#grid').datagrid('getSelected');
                       if (selected) {
                           window.open('@Url.Content("AmbulanceStateDetial?AmbCode=")' + selected.AmbCode);
                               //$('#divIndex').dialog('open');
                           }
                       else {
                           $.messager.alert('提示', '请选择数据行', 'info', function () {
                           });
                       }
                   }
               }
                ]
            })
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#grid");
        }

        //查询
        function reSearch() {
            $('#grid').datagrid({
                pageNumber: 1,//点击查询返回第一页
                queryParams: {
                    center: $('#center').combobox('getValues').join(','),
                    station: $('#station').combobox('getValues').join(','),
                    actualNumber: $('#actualNumber').combobox('getValue'),
                    ambulanceNumber: $('#ambulanceNumber').textbox('getValue'),
                    driver: $('#driver').combobox('getValue'),
                    doctor: $('#doctor').combobox('getValue'),
                    nurse: $('#nurse').combobox('getValue'),
                    stretcher: $('#stretcher').combobox('getValue'),
                    workState: $('#workState').combobox('getValue')
                }
            })
        }
    </script>
}
<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'车辆状态列表',iconCls:'icon-custom-Entry'">
        <div id="SearchBar" data-options="region:'center'" style="overflow: hidden; padding: 10px">
            <table style="width:99%" cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td align="right" valign="middle" width="9%">分中心：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="center" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="9%">分站：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="station" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="9%">实际标识：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="actualNumber" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="9%">车牌号码：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="ambulanceNumber" class="easyui-textbox" style="width:150px" />
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle" width="9%">司机：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="driver" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="9%">医生：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="doctor" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="9%">担架员：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="stretcher" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td align="right" valign="middle" width="9%">工作状态：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="workState" class="easyui-combobox" style="width:150px" />
                    </td>
                </tr>
                <tr>
                    <td align="right" valign="middle" width="9%">护士：</td>
                    <td align="right" valign="middle" width="13%">
                        <input id="nurse" class="easyui-combobox" style="width:150px" />
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td align="center" valign="middle" width="11%">
                        <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="grid"></table>
        </div>
    </div>
</div>
@*@Html.Partial("~/Areas/DD/Views/AmbulanceState/AmbulanceStateDetial.cshtml")*@

